<template>
  <view>
    <view class="top_search">
      <MySearch @click.native="goSearch"></MySearch>
    </view>
    
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
      <swiper-item v-for="(item,index) in SwiperList" :key="index">
        <navigator :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
          <image :src="item.image_src" ></image>
        </navigator>
      </swiper-item>
    </swiper>
    <view class="Nav">
      <view class="Nav_item" v-for="(item,index) in NavList" :key="index" @click="goClassify(item)">
        <image :src="item.image_src" mode=""></image>
      </view>
    </view>
    <view class="floor_item" v-for="(item,index) in floorData" :key="index">
      <view class="floor_item_top">
        <image :src="item.floor_title.image_src" mode=""></image>
      </view>
      <view class="floor_item_bottom">
        <view class="floor_item_bottom_left">
          <navigator :url="item.product_list[0].navigator_url">
            <image :src="item.product_list[0].image_src" mode="widthFix" :style="{width:item.product_list[0].image_width+'rpx'}"></image>
          </navigator>
        </view>
        <view class="floor_item_bottom_right">
           <navigator :url="i.navigator_url" :open-type="i.open_type" v-for="(i,inx) in item.product_list" :key="inx" v-if="inx>0">
             <image :src="i.image_src" alt="" ></image>
           </navigator>
        </view>
      </view>
    </view>
  </view>
  
</template>

<script>
    import getTabBarBadge from "../../mixins/getTabBarBadge.js" 
  export default {
    data() {
      return {
        // 导航图
        SwiperList: [],
        // 菜单
        NavList:[],
        // 底部楼层
        floorData:[]
      };
    },
    mixins:[getTabBarBadge],
    onLoad() {
      // 导航图
      this.getSwiperList()
      // 菜单
      this.getNavList()
      // 底部楼层数据
      this.getFloorData()
    },
    methods: {
      goSearch(){
        uni.navigateTo({
          url:"/subpkg/Search/Search"
        })
      },
      async getSwiperList(){
        const {data:res}=await uni.$http.get("/api/public/v1/home/swiperdata")
        if(res.meta.status!==200) return uni.$showMsg()
        this.SwiperList=res.message
      },
      async getNavList(){
        const {data:res}=await uni.$http.get("/api/public/v1/home/catitems")
        if(res.meta.status!==200) return uni.$showMsg("Nav菜单请求失败!")
        this.NavList=res.message  
      },
      goClassify(item){
        if(item.name==="分类"){
          uni.switchTab({
            url:"/pages/cate/cate"
          })
        }
      },
      async getFloorData(){
        let {data:res}=await uni.$http.get('/api/public/v1/home/floordata')
        if(res.meta.status!==200) return uni.$showMsg("底部楼层数据获取失败！")
        res.message.forEach(item=>{
          item.product_list.forEach(ele=>{
           ele.navigator_url=ele.navigator_url.replace("/pages/goods_list",'/subpkg/goods_list/goods_list')
          })
        })
        this.floorData=res.message
      }
    }
    
  }
</script>

<style lang="scss">
  .top_search{
    position: sticky;
    top: 0;
    z-index: 999;
  }
  swiper{
    
    height:330rpx;
    swiper-item{
      height: 100%;
      width: 100%;
      navigator,image{
        height:100%;
        width:100%
      }
    }
  }
.Nav{
  display:flex;
  justify-content: space-around;
  height:140rpx;
  margin: 20rpx 0;
  .Nav_item{
    height:128rpx;
    width: 140rpx;
    image{
      width: 100%;
      height: 100%;
    }
  }
}
.floor_item{
  margin-top: 10rpx;
  display: flex;
  flex-direction: column;
  .floor_item_top{
    height: 60rpx;
    image{
      width: 100%;
      height: 100%;
    }
  }
  .floor_item_bottom{
    width: 98%;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    .floor_item_bottom_right{
      display: flex;
      flex: 1;
      justify-content: space-between;
      flex-wrap: wrap;
      navigator{
        width: 48%;
        height: 48%;
        image{
          height: 100%;
          width: 100%;
        }
      }
    }
    }
}
</style>
